package com.example.bookstore.controller;

import com.example.bookstore.entity.Notice;
import com.example.bookstore.form.bookform.InsertBookForm;
import com.example.bookstore.form.noticeform.InsertNoticeForm;
import com.example.bookstore.form.noticeform.UpdateNoticeForm;
import com.example.bookstore.service.NoticeService;
import com.example.bookstore.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;

@Slf4j
@Api(value = "用户操作接口", tags = {"公告栏管理"})
@RestController
@RequestMapping("/NoticeController")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    @ApiOperation("添加一条新的公告")
    @PostMapping("/InsertNotice")
    public ResultVO InsertNotice(InsertNoticeForm insertNoticeForm) throws ParseException {
        return noticeService.InsertNotice(insertNoticeForm);
    }

    @ApiOperation("编辑公告")
    @PostMapping("/UpdateNotice")
    public ResultVO UpdateNotice(UpdateNoticeForm updateNoticeForm) {
        return noticeService.UpdateNotice(updateNoticeForm);
    }

    @ApiOperation("删除公告")
    @PostMapping("/DeleteNotice")
    public ResultVO DeleteNotice(Integer noticeId) {
        return noticeService.DeleteNotice(noticeId);
    }

    @ApiOperation("通过id查询公告")
    @PostMapping("/SelectNoticeById")
    public ResultVO SelectNoticeById(Integer noticeId) {
        return noticeService.SelectNoticeById(noticeId);
    }

    @ApiOperation("通过标题模糊查询公告")
    @PostMapping("/SelectNoticeByTitle")
    public ResultVO SelectNoticeByTitle(String title) {
        return noticeService.SelectNoticeByTitle(title);
    }

    @ApiOperation("获取当前最新的一条通知")
    @PostMapping("/ShowNewNotice")
    public ResultVO ShowNewNotice() {
        return noticeService.ShowNewNotice();
    }

    @ApiOperation("显示所有公告")
    @PostMapping("/ShowAllNotice")
    public ResultVO ShowAllNotice() {
        return noticeService.ShowAllNotice();
    }

}
